package com.hdu.other.tanxin;

import java.util.Arrays;

public class lc1029 {
    class Solution {
        public int twoCitySchedCost(int[][] costs) {
            int ans = 0;
            int[] arr = new int[costs.length];
            for (int i = 0; i < costs.length; i++){
                ans += costs[i][0];
                arr[i] = costs[i][1] - costs[i][0];
            }
            Arrays.sort(arr);
            for (int i = 0; i < costs.length / 2; i++){
                ans += arr[i];
            }
            return ans;
        }
    }
}
